/**   
 * @文件名称: AdminAction.java
 * @类路径: com.tdcms.cms.manage.action.user
 * @描述: TODO
 * @公司：昆明天度网络信息科技有限公司
 * @作者：李兴建
 * @时间：2013-7-23 下午05:22:28
 * @版本：V1.0   
 */

package com.lxj.cms.manage.action.user;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.hibernate.Criteria;
import org.hibernate.criterion.Order;

import com.lxj.cms.manage.action.ManageBaseAction;
import com.lxj.core.action.IBaseAction;
import com.lxj.core.entity.SYSAdmin;

/**
 * @类功能说明：
 * @类修改者：
 * @修改日期：
 * @修改说明：
 * @公司：昆明天度网络信息科技有限公司
 * @作者：李兴建
 * @创建时间：2013-7-23 下午05:22:28
 * @版本：V1.0
 */
@SuppressWarnings("serial")
@Results( { @Result(name = "index", location = "/WEB-INF/admin/admin/admin.jsp"), @Result(name = "userGropEdit", location = "/WEB-INF/cmsManage/user/userGropEdit.jsp") })
public class AdminAction extends ManageBaseAction implements IBaseAction {
	private SYSAdmin user;

	private String ids;

	@Override
	public void dataList() {
		Criteria criteria = this.createCriteria(SYSAdmin.class);
		criteria.addOrder(Order.desc("beanLastModidyfiTime"));
		this.setResult(criteria);
	}

	@Override
	public String editPage() {
		user = this.getBaseService().findById(this.getOptionId(), SYSAdmin.class);
		this.setResult(user);
		return null;
	}

	@Override
	public String index() {
		//Criteria criteria = this.createCriteria(SYSAdmin.class);
		//criteria.addOrder(Order.desc("beanLastModidyfiTime"));
		return "index";
	}

	@Override
	public String preservation() {
		Map<Object, Object> map = new HashMap<Object, Object>();
		try {
			this.getBaseService().saveOrUpdate(user);
			map.put("success", true);
		} catch (Exception e) {
			e.printStackTrace();
			map.put("failure", true);
			map.put("msg", "保存失败，请重试");
		}
		this.setResult(map);
		return null;
	}

	@Override
	public String remove() {
		Map<Object, Object> map = new HashMap<Object, Object>();
		try {
			if (StringUtils.isNotEmpty(this.getIds())) {
				String[] idsTemp = this.getIds().split(":");
				for (String str : idsTemp) {
					if (StringUtils.isEmpty(str)) {
						continue;
					}
					try {
						Long id = Long.parseLong(str);
						if(null==id){
							continue;
						}
						this.getBaseService().delete(id, SYSAdmin.class);
					} catch (Exception e) {
						e.printStackTrace();
						continue;
					}

				}
			}

			map.put("success", true);
		} catch (Exception e) {
			e.printStackTrace();
			map.put("failure", true);
			map.put("msg", "删除失败，请重试");
		}
		this.setResult(map);
		return null;
	}

	public SYSAdmin getUser() {
		return user;
	}

	public void setUser(SYSAdmin user) {
		this.user = user;
	}

	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}

}
